package router

import (
	"miao/casbin"
	"miao/config"
	"miao/router/controller"

	"github.com/gin-gonic/gin"
)

func Router() *gin.Engine {
	ginServer := gin.Default()
	//跨域
	ginServer.Use(config.Cors)
	ginServer.Use(casbin.NewEnforcer())
	authGroup := ginServer.Group("auth")
	{
		authGroup.POST("/login", controller.Login)
		authGroup.POST("/register", controller.Register)
		authGroup.GET("/info", controller.Info)
	}

	clockGroup := ginServer.Group("clock")
	{
		clockGroup.GET("/event/:eventId", controller.ClockByEventId)
	}

	ossGroup := ginServer.Group("oss")
	{
		ossGroup.POST("/upload", controller.OSSUploadHandler)
		ossGroup.GET("/download/:file", controller.OssDownloadHandler)
		ossGroup.GET("/preview/:file", controller.OssPreviewHandler)
		ossGroup.GET("/page", controller.PageByOss)
		ossGroup.DELETE("/:id", controller.DropFile)
	}

	userGroup := ginServer.Group("user")
	{
		userGroup.GET("/page", controller.UserPage)
		userGroup.DELETE("/:userId", controller.UserDelete)
		userGroup.POST("/save", controller.SaveUser) // 新增用户
	}

	roleGroup := ginServer.Group("role")
	{
		roleGroup.GET("/page", controller.Page)             // 分页查询角色
		roleGroup.POST("/save", controller.SaveRole)        // 保存角色
		roleGroup.DELETE("/:roleId", controller.DeleteRole) // 删除角色
	}

	return ginServer
}
